home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 3.iso / dist / fw_elisp-intro.idb / usr / freeware / info / emacs-lisp-intro.info-11.z / emacs-lisp-intro.info-11
Encoding:
GNU Info File  |  1998-10-28  |  47.9 KB  |  1,267 lines

  1. This is Info file emacs-lisp-intro.info, produced by Makeinfo version
  2. 1.67 from the input file emacs-lisp-intro.texi.
  3.  
  4.    This is an introduction to `Programming in Emacs Lisp', for people
  5. who are not programmers.
  6.  
  7.    Edition 1.05, 21 October 1997
  8.  
  9.    Copyright (C) 1990, '91, '92, '93, '94, '95, '97 Free Software
  10. Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided also
  18. that the sections entitled "Copying" and "GNU General Public License"
  19. are included exactly as in the original, and provided that the entire
  20. resulting derived work is distributed under the terms of a permission
  21. notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Free Software Foundation.
  27.  
  28. 
  29. File: emacs-lisp-intro.info,  Node: Text and Auto-fill,  Next: Mail Aliases,  Prev: Beginning a .emacs File,  Up: Emacs Initialization
  30.  
  31. Text and Auto Fill Mode
  32. =======================
  33.  
  34.    Now we come to the part that `turns on' Text mode and Auto Fill mode.
  35.  
  36.      ;;; Text mode and Auto Fill mode
  37.      ; The next two lines put Emacs into Text mode
  38.      ; and Auto Fill mode, and are for writers who
  39.      ; want to start writing prose rather than code.
  40.      
  41.      (setq default-major-mode 'text-mode)
  42.      (add-hook 'text-mode-hook 'turn-on-auto-fill)
  43.  
  44.    Here is the first part of this `.emacs' file that does something
  45. besides remind a forgetful human!
  46.  
  47.    The first of the two lines in parentheses tells Emacs to turn on Text
  48. mode when you find a file, *unless* that file should go into some other
  49. mode, such as C mode.
  50.  
  51.    When Emacs reads a file, it looks at the extension to the file name,
  52. if any.  (The extension is the part that comes after a `.'.)  If the
  53. file ends with a `.c' or `.h' extension then Emacs turns on C mode.
  54. Also, Emacs looks at first nonblank line of the file; if the line says
  55. `-*- C -*-', Emacs turns on C mode.  Emacs possesses a list of
  56. extensions and specifications that it uses automatically.  In addition,
  57. Emacs looks near the last page for a per-buffer, "local variables
  58. list", if any.
  59.  
  60.    *Note How Major Modes are Chosen: (emacs)Choosing Modes.
  61.  
  62.    *Note Local Variables in Files: (emacs)File Variables.
  63.  
  64.    Now, back to the `.emacs' file.
  65.  
  66.    Here is the line again; how does it work?
  67.  
  68.      (setq default-major-mode 'text-mode)
  69.  
  70. This line is a short, but complete Emacs Lisp expression.
  71.  
  72.    We are already familiar with `setq'.  It sets the following variable,
  73. `default-major-mode', to the subsequent value, which is `text-mode'.
  74. The single quote mark before `text-mode' tells Emacs to deal directly
  75. with the `text-mode' variable, not with whatever it might stand for.
  76. *Note Setting the Value of a Variable: set & setq, for a reminder of
  77. how `setq' works.  The main point is that there is no difference
  78. between the procedure you use to set a value in your `.emacs' file and
  79. the procedure you use anywhere else in Emacs.
  80.  
  81.    Here is the second line:
  82.  
  83.      (add-hook 'text-mode-hook 'turn-on-auto-fill)
  84.  
  85. In this line, the `add-hook' command, adds `turn-on-auto-fill' to the
  86. variable called `text-mode-hook'.  `turn-on-auto-fill' is the name of a
  87. program, that, you guessed it!, turns on Auto Fill mode.
  88.  
  89.    Every time Emacs turns on Text mode, Emacs runs the commands `hooked'
  90. onto Text mode.  So every time Emacs turns on Text mode, Emacs also
  91. turns on Auto Fill mode.
  92.  
  93.    In brief, the first line causes Emacs to enter Text mode when you
  94. edit a file, unless the file name extension, first non-blank line, or
  95. local variables tell Emacs otherwise.
  96.  
  97.    Text mode among other actions, sets the syntax table to work
  98. conveniently for writers.  In Text mode, Emacs considers an apostrophe
  99. as part of a word like a letter; but Emacs does not consider a period
  100. or a space as part of a word.  Thus, `M-f' moves you over `it's'.  On
  101. the other hand, in C mode, `M-f' stops just after the `t' of `it's'.
  102.  
  103.    The second line causes Emacs to turn on Auto Fill mode when it turns
  104. on Text mode.  In Auto Fill mode, Emacs automatically breaks a line
  105. that is too wide and brings the excessively wide part of the line down
  106. to the next line.  Emacs breaks lines between words, not within them.
  107.  
  108.    When Auto Fill mode is turned off, lines continue to the right as you
  109. type them.  Depending on how you set the value of `truncate-lines', the
  110. words you type either disappear off the right side of the screen, or
  111. else are shown, in a rather ugly and unreadable manner, as a
  112. continuation line on the screen.
  113.  
  114. 
  115. File: emacs-lisp-intro.info,  Node: Mail Aliases,  Next: Indent Tabs Mode,  Prev: Text and Auto-fill,  Up: Emacs Initialization
  116.  
  117. Mail Aliases
  118. ============
  119.  
  120.    Here is a `setq' to `turn on' mail aliases, along with more
  121. reminders.
  122.  
  123.      ;;; Mail mode
  124.      ; To enter mail mode, type `C-x m'
  125.      ; To enter RMAIL (for reading mail),
  126.      ; type `M-x rmail'
  127.      
  128.      (setq mail-aliases t)
  129.  
  130. This `setq' command sets the value of the variable `mail-aliases' to
  131. `t'.  Since `t' means true, the line says, in effect, "Yes, use mail
  132. aliases."
  133.  
  134.    Mail aliases are convenient short names for long email addresses or
  135. for lists of email addresses.  The file where you keep your `aliases'
  136. is `~/.mailrc'.  You write an alias like this:
  137.  
  138.      alias geo george@foobar.wiz.edu
  139.  
  140. When you write a message to George, address it to `geo'; the mailer
  141. will automatically expand `geo' to the full address.
  142.  
  143. 
  144. File: emacs-lisp-intro.info,  Node: Indent Tabs Mode,  Next: Keybindings,  Prev: Mail Aliases,  Up: Emacs Initialization
  145.  
  146. Indent Tabs Mode
  147. ================
  148.  
  149.    By default, Emacs inserts tabs in place of multiple spaces when it
  150. formats a region.  (For example, you might indent many lines of text
  151. all at once with the `indent-region' command.)  Tabs look fine on a
  152. terminal or with ordinary printing, but they produce badly indented
  153. output when you use TeX or Texinfo since TeX ignores tabs.
  154.  
  155.    The following turns off Indent Tabs mode:
  156.  
  157.      ;;; Prevent Extraneous Tabs
  158.      (setq-default indent-tabs-mode nil)
  159.  
  160.    Note that this line uses `setq-default' rather than the `setq'
  161. command that we have seen before.  The `setq-default' command sets
  162. values only in buffers that do not have their own local values for the
  163. variable.
  164.  
  165.    *Note Tabs vs. Spaces: (emacs)Just Spaces.
  166.  
  167.    *Note Local Variables in Files: (emacs)File Variables.
  168.  
  169. 
  170. File: emacs-lisp-intro.info,  Node: Keybindings,  Next: Loading Files,  Prev: Indent Tabs Mode,  Up: Emacs Initialization
  171.  
  172. Some Keybindings
  173. ================
  174.  
  175.    Now for some personal keybindings:
  176.  
  177.      ;;; Compare windows
  178.      (global-set-key "\C-cw" 'compare-windows)
  179.  
  180.    `compare-windows' is a nifty command that compares the text in your
  181. current window with text in the next window.  It makes the comparison
  182. by starting at point in each window, moving over text in each window as
  183. far as they match.  I use this command all the time.
  184.  
  185.    This also shows how to set a key globally, for all modes.
  186.  
  187.    The command is `global-set-key'.  It is followed by the keybinding.
  188. In a `.emacs' file, the keybinding is written as shown: `\C-c' stands
  189. for `control-c', which means `press the control key and the `c' key at
  190. the same time'.  The `w' means `press the `w' key'.  The keybinding is
  191. surrounded by double quotation marks.  In documentation, you would
  192. write this as `C-c w'.  (If you were binding a <META> key, such as
  193. `M-c', rather than a <CTL> key, you would write `\M-c'.  *Note
  194. Rebinding Keys in Your Init File: (emacs)Init Rebinding, for details.)
  195.  
  196.    The command invoked by the keys is `compare-windows'.  Note that
  197. `compare-windows' is preceded by a single quote; otherwise, Emacs would
  198. first try to evaluate the symbol to determine its value.
  199.  
  200.    These three things, the double quotation marks, the backslash before
  201. the `C', and the single quote mark are necessary parts of keybinding
  202. that I tend to forget.  Fortunately, I have come to remember that I
  203. should look at my existing `.emacs' file, and adapt what is there.
  204.  
  205.    As for the keybinding itself: `C-c w'.  This combines the prefix
  206. key, `C-c', with a single character, in this case, `w'.  This set of
  207. keys, `C-c' followed by a single character, is strictly reserved for
  208. individuals' own use.  If you ever write an extension to Emacs, please
  209. avoid taking any of these keys for public use.  Create a key like `C-c
  210. C-w' instead.  Otherwise, we will run out of `own' keys.
  211.  
  212.    Here is another keybinding, with a comment:
  213.  
  214.      ;;; Keybinding for `occur'
  215.      ; I use occur a lot, so let's bind it to a key:
  216.      (global-set-key "\C-co" 'occur)
  217.  
  218.    The `occur' command shows all the lines in the current buffer that
  219. contain a match for a regular expression.  Matching lines are shown in
  220. a buffer called `*Occur*'.  That buffer serves as a menu to jump to
  221. occurrences.
  222.  
  223.    Here is how to unbind a key, so it does not work:
  224.  
  225.      ;;; Unbind `C-x f'
  226.      (global-unset-key "\C-xf")
  227.  
  228.    There is a reason for this unbinding: I found I inadvertently typed
  229. `C-x f' when I meant to type `C-x C-f'.  Rather than find a file, as I
  230. intended, I accidentally set the width for filled text, almost always
  231. to a width I did not want.  Since I hardly ever reset my default width,
  232. I simply unbound the key.
  233.  
  234.    The following rebinds an existing key:
  235.  
  236.      ;;; Rebind `C-x C-b' for `buffer-menu'
  237.      (global-set-key "\C-x\C-b" 'buffer-menu)
  238.  
  239.    By default, `C-x C-b' runs the `list-buffers' command.  This command
  240. lists your buffers in *another* window.  Since I almost always want to
  241. do something in that window, I prefer the  `buffer-menu' command, which
  242. not only lists the buffers, but moves point into that window.
  243.  
  244. 
  245. File: emacs-lisp-intro.info,  Node: Loading Files,  Next: Autoload,  Prev: Keybindings,  Up: Emacs Initialization
  246.  
  247. Loading Files
  248. =============
  249.  
  250.    Many people in the GNU Emacs community have written extensions to
  251. Emacs.  As time goes by, these extensions are often included in new
  252. releases.  For example, the Calendar and Diary packages are now part of
  253. the standard Emacs version 19 distribution; they were not part of the
  254. standard Emacs version 18 distribution.
  255.  
  256.    (Calc, which I consider a vital part of Emacs, would be part of the
  257. standard distribution except that it is so large it is packaged
  258. separately.)
  259.  
  260.    You can use a `load' command to evaluate a complete file and thereby
  261. install all the functions and variables in the file into Emacs.  For
  262. example:
  263.  
  264.      (load "~/emacs/kfill")
  265.  
  266.    This evaluates, i.e. loads, the `kfill.el' file (or if it exists,
  267. the faster, byte compiled `kfill.elc' file) from the `emacs'
  268. sub-directory of your home directory.
  269.  
  270.    (`kfill.el' was adapted from Kyle E. Jones' `filladapt.el' package
  271. by Bob Weiner and "provides no muss, no fuss word wrapping and filling
  272. of paragraphs with hanging indents, included text from news and mail
  273. messages, and Lisp, C++, PostScript or shell comments." I use it all
  274. the time and hope it is incorporated into the standard distribution.)
  275.  
  276.    If you load many extensions, as I do, then instead of specifying the
  277. exact location of the extension file, as shown above, you can specify
  278. that directory as part of Emacs's `load-path'.  Then, when Emacs loads
  279. a file, it will search that directory as well as its default list of
  280. directories.  (The default list is specified in `paths.h' when Emacs is
  281. built.)
  282.  
  283.    The following command adds your `~/emacs' directory to the existing
  284. load path:
  285.  
  286.      ;;; Emacs Load Path
  287.      (setq load-path (cons "~/emacs" load-path))
  288.  
  289.    Incidentally, `load-library' is an interactive interface to the
  290. `load' function.  The complete function looks like this:
  291.  
  292.      (defun load-library (library)
  293.        "Load the library named LIBRARY.
  294.      This is an interface to the function `load'."
  295.        (interactive "sLoad library: ")
  296.        (load library))
  297.  
  298.    The name of the function, `load-library', comes from the use of
  299. `library' as a conventional synonym for `file'.  The source for the
  300. `load-library' command is in the `files.el' library.
  301.  
  302.    Another interactive command that does a slightly different job is
  303. `load-file'.  *Note Libraries of Lisp Code for Emacs: (emacs)Lisp
  304. Libraries, for information on the distinction between `load-library'
  305. and this command.
  306.  
  307. 
  308. File: emacs-lisp-intro.info,  Node: Autoload,  Next: Simple Extension,  Prev: Loading Files,  Up: Emacs Initialization
  309.  
  310. Autoloading
  311. ===========
  312.  
  313.    Instead of installing a function by loading the file that contains
  314. it, or by evaluating the function definition, you can make the function
  315. available but not actually install it until it is first called.  This
  316. is called "autoloading".
  317.  
  318.    When you execute an autoloaded function, Emacs automatically
  319. evaluates the file that contains the definition, and then calls the
  320. function.
  321.  
  322.    Emacs starts quicker with autoloaded functions, since their libraries
  323. are not loaded right away; but you need to wait a moment when you first
  324. use such a function, while its containing file is evaluated.
  325.  
  326.    Rarely used functions are frequently autoloaded.  The `loaddefs.el'
  327. library contains hundreds of autoloaded functions, from `bookmark-set'
  328. to `wordstar-mode'.  Of course, you may come to use a `rare' function
  329. frequently.  In this case, you should load that function's file with a
  330. `load' expression in your `.emacs' file.
  331.  
  332.    In my `.emacs' file for Emacs version 19.23, I load 17 libraries
  333. that contain functions that would otherwise be autoloaded.  (Actually,
  334. it would have been better to include these files in my `dumped' Emacs
  335. when I built it, but I forgot.  *Note Building Emacs: (elisp)Building
  336. Emacs, and the `INSTALL' file for more about dumping.)
  337.  
  338.    You may also want to include autoloaded expressions in your `.emacs'
  339. file.  `autoload' is a built-in function that takes up to five
  340. arguments, the final three of which are optional.  The first argument
  341. is the name of the function to be autoloaded; the second is the name of
  342. the file to be loaded.  The third argument is documentation for the
  343. function, and the fourth tells whether the function can be called
  344. interactively.  The fifth argument tells what type of
  345. object--`autoload' can handle a keymap or macro as well as a function
  346. (the default is a function).
  347.  
  348.    Here is a typical example:
  349.  
  350.      (autoload 'html-helper-mode
  351.        "html-helper-mode" "Edit HTML documents" t)
  352.  
  353. This expression autoloads the `html-helper-mode' function from the
  354. `html-helper-mode.el' file (or, if it exists, from the byte compiled
  355. file `html-helper-mode.elc'.)  The file must be located in a directory
  356. specified by `load-path'.  The documentation says that this is a mode
  357. to help you edit documents written in the HyperText Markup Language.
  358. You can call this mode interactively by typing `M-x html-helper-mode'.
  359. (You need to duplicate the function's regular documentation in the
  360. autoload expression because the regular function is not yet loaded, so
  361. its documentation is not available.)
  362.  
  363.    *Note Autoload: (elisp)Autoload, for more information.
  364.  
  365. 
  366. File: emacs-lisp-intro.info,  Node: Simple Extension,  Next: Keymaps,  Prev: Autoload,  Up: Emacs Initialization
  367.  
  368. A Simple Extension: `line-to-top-of-window'
  369. ===========================================
  370.  
  371.    Here is a simple extension to Emacs that moves the line point is on
  372. to the top of the window.  I use this all the time, to make text easier
  373. to read.
  374.  
  375.    You can put the following code into a separate file and then load it
  376. from your `.emacs' file, or you can include it within your `.emacs'
  377. file.
  378.  
  379.    Here is the definition:
  380.  
  381.      ;;; Line to top of window;
  382.      ;;; replace three keystroke sequence  C-u 0 C-l
  383.      (defun line-to-top-of-window ()
  384.        "Move the line point is on to top of window."
  385.        (interactive)
  386.        (recenter 0))
  387.  
  388.    Now for the keybinding.
  389.  
  390.    Although most of an Emacs version 18 `.emacs' file works with
  391. version 19, there are some differences (also, of course, there are new
  392. features in Emacs 19).
  393.  
  394.    In version 19 Emacs, you can write a function key like this: `[f6]'.
  395. In version 18, you must specify the key strokes sent by the keyboard
  396. when you press that function key.  For example, a Zenith 29 keyboard
  397. sends <ESC P> when I press its sixth function key; an Ann Arbor
  398. Ambassador keyboard sends <ESC O F>.  Write these keystrokes as `\eP'
  399. and `\eOF', respectively.
  400.  
  401.    In my version 18 `.emacs' file, I bind `line-to-top-of-window' to a
  402. key that depends on the type of terminal:
  403.  
  404.      (defun z29-key-bindings ()
  405.        "Function keybindings for Z29 terminal."
  406.        ;; ...
  407.        (global-set-key "\eP" 'line-to-top-of-window))
  408.      
  409.      (defun aaa-key-bindings ()
  410.        "Function keybindings for Ann Arbor Ambassador"
  411.        ;; ...
  412.        (global-set-key "\eOF" 'line-to-top-of-window))
  413.  
  414. (You can find out what a function key sends by typing the function key,
  415. and then typing `C-h l' (`view-lossage') which displays the last 100
  416. input keystrokes.)
  417.  
  418.    After specifying the key bindings, I evaluate an expression that
  419. chooses among keybindings, depending on the type of terminal I am
  420. using.  However, before doing that, I turn off the predefined, default
  421. terminal-specific keybindings, which overwrite bindings in the `.emacs'
  422. if they clash.
  423.  
  424.      ;;; Turn Off Predefined Terminal Keybindings
  425.      
  426.      ; The following turns off the predefined
  427.      ; terminal-specific keybindings such as the
  428.      ; vt100 keybindings in lisp/term/vt100.el.
  429.      ; If there are no predefined terminal
  430.      ; keybindings, or if you like them,
  431.      ; comment this out.
  432.      
  433.      (setq term-file-prefix nil)
  434.  
  435.    Here is the selection expression itself:
  436.  
  437.      (let ((term (getenv "TERM")))
  438.        (cond
  439.         ((equal term "z29") (z29-key-bindings))
  440.         ((equal term "aaa") (aaa-key-bindings))
  441.         (t (message
  442.             "No binding for terminal type %s."
  443.             term))))
  444.  
  445.    In Emacs version 19, function keys (as well as mouse button events
  446. and non-ASCII characters) are written within square brackets, without
  447. quotation marks.  I bind `line-to-top-of-window' to my <F6> function
  448. key like this:
  449.  
  450.      (global-set-key [f6] 'line-to-top-of-window)
  451.  
  452. Much simpler!
  453.  
  454.    For more information, see *Note Rebinding Keys in Your Init File:
  455. (emacs)Init Rebinding.
  456.  
  457.    If you run both Emacs 18 and Emacs 19, you can select which code to
  458. evaluate with the following conditional:
  459.  
  460.      (if (string=
  461.           (int-to-string 18)
  462.           (substring (emacs-version) 10 12))
  463.          ;; evaluate version 18 code
  464.          (progn
  465.             ... )
  466.        ;; else evaluate version 19 code
  467.        ...
  468.  
  469. 
  470. File: emacs-lisp-intro.info,  Node: Keymaps,  Next: X11 Colors,  Prev: Simple Extension,  Up: Emacs Initialization
  471.  
  472. Keymaps
  473. =======
  474.  
  475.    Emacs uses "keymaps" to record which keys call which commands.
  476. Specific modes, such as C mode or Text mode, have their own keymaps;
  477. the mode-specific keymaps override the global map that is shared by all
  478. buffers.
  479.  
  480.    The `global-set-key' function binds, or rebinds, the global keymap.
  481. For example, the following binds the key `C-c C-l' to the function
  482. `line-to-top-of-window':
  483.  
  484.      (global-set-key "\C-c\C-l" 'line-to-top-of-window))
  485.  
  486.    Mode-specific keymaps are bound using the `define-key' function,
  487. which takes a specific keymap as an argument, as well as the key and
  488. the command.  For example, my `.emacs' file contains the following
  489. expression to bind the `texinfo-insert-@group' command to `C-c C-c g':
  490.  
  491.      (define-key texinfo-mode-map "\C-c\C-cg"
  492.        'texinfo-insert-@group)
  493.  
  494. The `texinfo-insert-@group' function itself is a little extension to
  495. Texinfo mode that inserts `@group' into a Texinfo file.  I use this
  496. command all the time and prefer to type the three strokes `C-c C-c g'
  497. rather than the six strokes `@ g r o u p'.  (`@group' and its matching
  498. `@end group' are commands that keep all enclosed text together on one
  499. page; many multi-line examples in this book are surrounded by `@group
  500. ... @end group'.)
  501.  
  502.    Here is the `texinfo-insert-@group' function definition:
  503.  
  504.      (defun texinfo-insert-@group ()
  505.        "Insert the string @group in a Texinfo buffer."
  506.        (interactive)
  507.        (beginning-of-line)
  508.        (insert "@group\n"))
  509.  
  510.    (Of course, I could have used Abbrev mode to save typing, rather than
  511. write a function to insert a word; but I prefer  key strokes consistent
  512. with other Texinfo mode key bindings.)
  513.  
  514.    You will see numerous `define-key' expressions in `loaddefs.el' as
  515. well as in the various mode libraries, such as `c-mode.el' and
  516. `lisp-mode.el'.
  517.  
  518.    *Note Customizing Key Bindings: (emacs)Key Bindings, and *Note
  519. Keymaps: (elisp)Keymaps, for more information about keymaps.
  520.  
  521. 
  522. File: emacs-lisp-intro.info,  Node: X11 Colors,  Next: V19 Miscellaneous,  Prev: Keymaps,  Up: Emacs Initialization
  523.  
  524. X11 Colors
  525. ==========
  526.  
  527.    You can specify colors when you use Emacs version 19 with the MIT X
  528. Windowing system.  (All the previous examples should work with both
  529. Emacs version 18 and Emacs version 19; this works only with Emacs
  530. version 19.)
  531.  
  532.    I hate the default colors and specify my own.
  533.  
  534.    Most of my specifications are in various X initialization files.  I
  535. wrote notes to myself in my `.emacs' file to remind myself what I did:
  536.  
  537.      ;; I use TWM for window manager;
  538.      ;; my ~/.xsession file specifies:
  539.      ;    xsetroot -solid navyblue -fg white
  540.  
  541. Actually, the root of the X window is not part of Emacs at all, but I
  542. like the reminder anyhow.
  543.  
  544.      ;; My ~/.Xresources file specifies:
  545.      ;     XTerm*Background:    sky blue
  546.      ;     XTerm*Foreground:    white
  547.      ;     emacs*geometry:      =80x40+100+0
  548.      ;     emacs*background:    blue
  549.      ;     emacs*foreground:    grey97
  550.      ;     emacs*cursorColor:   white
  551.      ;     emacs*pointerColor:  white
  552.  
  553.    Here are the expressions in my `.emacs' file that set values:
  554.  
  555.      ;;; Set highlighting colors for isearch and drag
  556.      (set-face-foreground 'highlight "white" )
  557.      (set-face-background 'highlight "slate blue")
  558.      (set-face-background 'region    "slate blue")
  559.      (set-face-background
  560.       'secondary-selection "turquoise")
  561.      
  562.      ;; Set calendar highlighting colors
  563.      (setq calendar-load-hook
  564.            '(lambda ()
  565.               (set-face-foreground 'diary-face   "skyblue")
  566.               (set-face-background 'holiday-face "slate blue")
  567.               (set-face-foreground 'holiday-face "white")))
  568.  
  569.    The various shades of blue soothe my eye and prevent me from seeing
  570. the screen flicker.
  571.  
  572. 
  573. File: emacs-lisp-intro.info,  Node: V19 Miscellaneous,  Next: Mode Line,  Prev: X11 Colors,  Up: Emacs Initialization
  574.  
  575. V19 Miscellaneous
  576. =================
  577.  
  578.    Here are a few miscellaneous settings for version 19 Emacs:
  579.  
  580.    - Automatically resize the minibuffer as needed:
  581.  
  582.           (resize-minibuffer-mode 1)
  583.           (setq resize-minibuffer-mode t)
  584.  
  585.    - Turn on highlighting for search strings:
  586.  
  587.           (setq search-highlight t)
  588.  
  589.    - Set every frame to show a menu bar and to come forward when you
  590.      move the mouse onto it.
  591.  
  592.           (setq default-frame-alist
  593.                 '((menu-bar-lines . 1)
  594.                   (auto-lower . t)
  595.                   (auto-raise . t)))
  596.  
  597.    - Set the shape and color of the mouse cursor:
  598.           ; Cursor shapes are defined in
  599.           ; `/usr/include/X11/cursorfont.h';
  600.           ; for example, the `target' cursor is number 128;
  601.           ; the `top_left_arrow' cursor is number 132.
  602.           
  603.           (let ((mpointer (x-get-resource "*mpointer"
  604.                                           "*emacs*mpointer")))
  605.             ;; If you have not set your mouse pointer
  606.             ;;     then sent it, otherwise leave as is:
  607.             (if (eq mpointer nil)
  608.                 (setq mpointer "132")) ; top_left_arrow
  609.             (setq x-pointer-shape (string-to-int mpointer))
  610.             (set-mouse-color "white"))
  611.  
  612. 
  613. File: emacs-lisp-intro.info,  Node: Mode Line,  Prev: V19 Miscellaneous,  Up: Emacs Initialization
  614.  
  615. A Modified Mode Line
  616. ====================
  617.  
  618.    Finally, a feature I really like: a modified mode line.
  619.  
  620.    Since I sometimes work over a network, I replaced the `Emacs: ' that
  621. is normally written on the left hand side of the mode line by the name
  622. of the system--otherwise, I forget which machine I am using.  In
  623. addition, I list the default directory lest I lose track of where I am,
  624. and I specify the line point is on, with `Line' spelled out.  My
  625. `.emacs' file looks like this:
  626.  
  627.      (setq mode-line-system-identification
  628.        (substring (system-name) 0
  629.                   (string-match "\\..+" (system-name))))
  630.      
  631.      (setq default-mode-line-format
  632.            (list ""
  633.                  'mode-line-modified
  634.                  "<"
  635.                  'mode-line-system-identification
  636.                  "> "
  637.                  "%14b"
  638.                  " "
  639.                  'default-directory
  640.                  " "
  641.                  "%[("
  642.                  'mode-name
  643.                  'minor-mode-alist
  644.                  "%n"
  645.                  'mode-line-process
  646.                  ")%]--"
  647.                   "Line %l--"
  648.                  '(-3 . "%P")
  649.                  "-%-"))
  650.      
  651.      ;; Start with new default.
  652.      (setq mode-line-format default-mode-line-format)
  653.  
  654. I set the *default* mode line format so as to permit various modes,
  655. such as Info, to override it.  Many elements in the list are
  656. self-explanatory:  `mode-line-modified' is a variable the tells whether
  657. the buffer has been modified, `mode-name' tells the name of the mode,
  658. and so on.
  659.  
  660.    The `"%14b"' displays the current buffer name (using the
  661. `buffer-name' function with which we are familiar); the `14' specifies
  662. the maximum number of characters that will be displayed.  When a name
  663. has fewer characters, whitespace is added to fill out to this number.
  664. `%[' and `%]' cause a pair of square brackets to appear for each
  665. recursive editing level.  `%n' says `Narrow' when narrowing is in
  666. effect.  `%P' tells you the percentage of the buffer that is above the
  667. bottom of the window, or `Top', `Bottom', or `All'.  (A lower case `p'
  668. tell you the percentage above the *top* of the window.)  `%-' inserts
  669. enough dashes to fill out the line.
  670.  
  671.    In and after Emacs version 19.29, you can use `frame-title-format'
  672. to set the title of an Emacs frame.  This variable has the same
  673. structure as `mode-line-format'.
  674.  
  675.    Mode line formats are described in *Note Mode Line Format:
  676. (elisp)Mode Line Format.
  677.  
  678.    Remember, "You don't have to like Emacs to like it" -- your own
  679. Emacs can have different colors, different commands, and different keys
  680. than a default Emacs.
  681.  
  682.    On the other hand, if you want to bring up a plain `out of the box'
  683. Emacs, with no customization, type:
  684.  
  685.      emacs -q
  686.  
  687. This will start an Emacs that does *not* load your `~/.emacs'
  688. initialization file.  A plain, default Emacs.  Nothing more.
  689.  
  690. 
  691. File: emacs-lisp-intro.info,  Node: Debugging,  Next: Conclusion,  Prev: Emacs Initialization,  Up: Top
  692.  
  693. Debugging
  694. *********
  695.  
  696.    GNU Emacs has two debuggers, `debug' and `edebug'.  The first is
  697. built into the internals of Emacs and is always with you; the second is
  698. an extension to Emacs that has become part of the standard distribution
  699. in version 19.
  700.  
  701.    Both debuggers are described extensively in *Note Debugging Lisp
  702. Programs: (elisp)Debugging.  In this chapter, I will walk through a
  703. short example of each.
  704.  
  705. * Menu:
  706.  
  707. * debug::                       How to use the built-in debugger.
  708. * debug-on-entry::              Start debugging when you call a function.
  709. * debug-on-quit::               Start debugging when you quit with `C-g'.
  710. * edebug::                      How to use Edebug, a source level debugger.
  711. * Debugging Exercises::
  712.  
  713. 
  714. File: emacs-lisp-intro.info,  Node: debug,  Next: debug-on-entry,  Prev: Debugging,  Up: Debugging
  715.  
  716. `debug'
  717. =======
  718.  
  719.    Suppose you have written a function definition that is intended to
  720. return the sum of the numbers 1 through a given number.  (This is the
  721. `triangle' function discussed earlier.  *Note Example with Decrementing
  722. Counter: Decrementing Example, for a discussion.)
  723.  
  724.    However, your function definition has a bug.  You have mistyped `1='
  725. for `1-'.  Here is the broken definition:
  726.  
  727.      (defun triangle-bugged (number)
  728.        "Return sum of numbers 1 through NUMBER inclusive."
  729.        (let ((total 0))
  730.          (while (> number 0)
  731.            (setq total (+ total number))
  732.            (setq number (1= number)))      ; Error here.
  733.          total))
  734.  
  735.    If you are reading this in Info, you can evaluate this definition in
  736. the normal fashion.  You will see `triangle-bugged' appear in the echo
  737. area.
  738.  
  739.    Now evaluate the `triangle-bugged' function with an argument of 4:
  740.  
  741.      (triangle-bugged 4)
  742.  
  743. You will produce an error message that says:
  744.  
  745.      Symbol's function definition is void: 1=
  746.  
  747. In practice, for a bug as simple as this, this error message will tell
  748. you what you need to know to correct the definition.  However, suppose
  749. you are not quite certain what is going on?
  750.  
  751.    You can turn on debugging by setting the value of `debug-on-error'
  752. to `t':
  753.  
  754.      (setq debug-on-error t)
  755.  
  756. This causes Emacs to enter the debugger next time it encounters an
  757. error.
  758.  
  759. You can turn off  `debug-on-error' by setting it to `nil':
  760.  
  761.      (setq debug-on-error nil)
  762.  
  763. Set `debug-on-error' to `t' and evaluate the following:
  764.  
  765.      (triangle-bugged 4)
  766.  
  767. This time, Emacs will create a buffer called `*Backtrace*' that looks
  768. like this:
  769.  
  770.      ---------- Buffer: *Backtrace* ----------
  771.      Signalling: (void-function 1=)
  772.        (1= number))
  773.        (setq number (1= number)))
  774.        (while (> number 0) (setq total (+ total number))
  775.              (setq number (1= number))))
  776.        (let ((total 0)) (while (> number 0) (setq total ...)
  777.              (setq number ...)) total))
  778.        triangle-bugged(4)
  779.        eval((triangle-bugged 4))
  780.        eval-last-sexp(nil)
  781.      * call-interactively(eval-last-sexp)
  782.      ---------- Buffer: *Backtrace* ----------
  783.  
  784. (I have reformatted this example slightly; the debugger does not fold
  785. long lines.)
  786.  
  787.    You read the `*Backtrace*' buffer from the bottom up; it tells you
  788. what Emacs did that led to the error.  In this case, what Emacs did was
  789. make an interactive call to `C-x C-e' (`eval-last-sexp'), which led to
  790. the evaluation of the `triangle-bugged' expression.  Each line above
  791. tells you what the Lisp interpreter evaluated next.
  792.  
  793.    The third line from the top of the buffer is
  794.  
  795.      (setq number (1= number))
  796.  
  797. Emacs tried to evaluate this expression; in order to do so, it tried to
  798. evaluate the inner expression shown on the second line from the top:
  799.  
  800.      (1= number)
  801.  
  802. This is where the error occurred; as the top line says:
  803.  
  804.      Signalling: (void-function 1=)
  805.  
  806. You can correct the mistake, re-evaluate the function definition, and
  807. then run your test again.
  808.  
  809.    If you are reading this in Info, you can now turn off
  810. `debug-on-error' by setting it to `nil':
  811.  
  812.      (setq debug-on-error nil)
  813.  
  814. 
  815. File: emacs-lisp-intro.info,  Node: debug-on-entry,  Next: debug-on-quit,  Prev: debug,  Up: Debugging
  816.  
  817. `debug-on-entry'
  818. ================
  819.  
  820.    A second way to start `debug' on a function is to enter the debugger
  821. when you call the function.  You can do this by calling
  822. `debug-on-entry'.
  823.  
  824. Type:
  825.  
  826.      M-x debug-on-entry RET triangle-bugged RET
  827.  
  828. Now, evaluate the following:
  829.  
  830.      (triangle-bugged 5)
  831.  
  832. Emacs will create a `*Backtrace*' buffer and tell you that it is
  833. beginning to evaluate the `triangle-bugged' function:
  834.  
  835.      ---------- Buffer: *Backtrace* ----------
  836.      Entering:
  837.      * triangle-bugged(5)
  838.        eval((triangle-bugged 5))
  839.        eval-last-sexp(nil)
  840.      * call-interactively(eval-last-sexp)
  841.      ---------- Buffer: *Backtrace* ----------
  842.  
  843.    In the `*Backtrace*' buffer, type `d'.  Emacs will evaluate the
  844. first expression in `triangle-bugged'; the buffer will look like this:
  845.  
  846.      ---------- Buffer: *Backtrace* ----------
  847.      Beginning evaluation of function call form:
  848.      * (let ((total 0)) (while (> number 0) (setq total ...)
  849.              (setq number ...)) total))
  850.        triangle-bugged(5)
  851.      * eval((triangle-bugged 5))
  852.        eval-last-sexp(nil)
  853.      * call-interactively(eval-last-sexp)
  854.      ---------- Buffer: *Backtrace* ----------
  855.  
  856. Now, type `d' again, eight times, slowly.  Each time you type `d',
  857. Emacs will evaluate another expression in the function definition.
  858. Eventually,  the buffer will look like this:
  859.  
  860.      ---------- Buffer: *Backtrace* ----------
  861.      Beginning evaluation of function call form:
  862.      * (setq number (1= number)))
  863.      * (while (> number 0) (setq total (+ total number))
  864.              (setq number (1= number))))
  865.      * (let ((total 0)) (while (> number 0)
  866.              (setq total ...) (setq number ...)) total))
  867.        triangle-bugged(5)
  868.      * eval((triangle-bugged 5))
  869.        eval-last-sexp(nil)
  870.      * call-interactively(eval-last-sexp)
  871.      ---------- Buffer: *Backtrace* ----------
  872.  
  873. Finally, after you type `d' two more times, Emacs will reach the error,
  874. and the top two lines of the `*Backtrace*' buffer will look like this:
  875.  
  876.      ---------- Buffer: *Backtrace* ----------
  877.      Signalling: (void-function 1=)
  878.      * (1= number))
  879.      ...
  880.      ---------- Buffer: *Backtrace* ----------
  881.  
  882.    By typing `d', you were able to step through the function.
  883.  
  884.    You can quit a `*Backtrace*' buffer by typing `q'; this quits the
  885. trace, but does not cancel `debug-on-entry'.
  886.  
  887.    To cancel the effect of `debug-on-entry', call
  888. `cancel-debug-on-entry' and the name of the function, like this:
  889.  
  890.      M-x cancel-debug-on-entry RET triangle-debugged RET
  891.  
  892. (If you are reading this in Info, cancel `debug-on-entry' now.)
  893.  
  894. 
  895. File: emacs-lisp-intro.info,  Node: debug-on-quit,  Next: edebug,  Prev: debug-on-entry,  Up: Debugging
  896.  
  897. `debug-on-quit' and `(debug)'
  898. =============================
  899.  
  900.    In addition to setting `debug-on-error' or calling `debug-on-entry',
  901. there are two other ways to start `debug'.
  902.  
  903.    You can start `debug' whenever you type `C-g' (`keyboard-quit') by
  904. setting the variable `debug-on-quit' to `t'.  This is useful for
  905. debugging infinite loops.
  906.  
  907.    Or, you can insert a line that says `(debug)' into your code where
  908. you want the debugger to start, like this:
  909.  
  910.      (defun triangle-bugged (number)
  911.        "Return sum of numbers 1 through NUMBER inclusive."
  912.        (let ((total 0))
  913.          (while (> number 0)
  914.            (setq total (+ total number))
  915.            (debug)                         ; Start debugger.
  916.            (setq number (1= number)))      ; Error here.
  917.          total))
  918.  
  919.    The `debug' function is described in detail in *Note The Lisp
  920. Debugger: (elisp)Debugger.
  921.  
  922. 
  923. File: emacs-lisp-intro.info,  Node: edebug,  Next: Debugging Exercises,  Prev: debug-on-quit,  Up: Debugging
  924.  
  925. The `edebug' Source Level Debugger
  926. ==================================
  927.  
  928.    Edebug normally displays the source of the code you are debugging,
  929. with an arrow at the left that shows which line you are currently
  930. executing.
  931.  
  932.    You can walk through the execution of a function, line by line, or
  933. run quickly until reaching a "breakpoint" where execution stops.
  934.  
  935.    Edebug is described in *Note Edebug: (elisp)edebug.
  936.  
  937.    Here is a bugged function definition for `triangle-recursively'.
  938. *Note Recursion in place of a counter: Recursive triangle function, for
  939. a review of it.  This example is presented without indentation to the
  940. left of the `defun', as explained below.
  941.  
  942. (defun triangle-recursively-bugged (number)
  943.   "Return sum of numbers 1 through NUMBER inclusive.
  944. Uses recursion."
  945.   (if (= number 1)
  946.       1
  947.     (+ number
  948.        (triangle-recursively-bugged
  949.         (1= number)))))               ; Error here.
  950.  
  951. Normally, you would install this definition by positioning your cursor
  952. after the function's closing parenthesis and typing `C-x C-e'
  953. (`eval-last-sexp') or else by positioning your cursor within the
  954. definition and typing `C-M-x' (`eval-defun').  (By default, the
  955. `eval-defun' command works only in Emacs Lisp mode or in Lisp
  956. Interactive mode.)
  957.  
  958.    However, to prepare this function definition for Edebug, you must
  959. first "instrument" the code using a different command.  In Emacs
  960. version 19, you can do this by positioning your cursor within the
  961. definition and typing the following:
  962.  
  963.      M-x edebug-defun RET
  964.  
  965. This will cause Emacs to load Edebug automatically if it is not already
  966. loaded, and properly instrument the function.  (After loading Edebug,
  967. you can use its standard keybindings, such as `C-u C-M-x' (`eval-defun'
  968. with a prefix argument) for `edebug-defun'.)
  969.  
  970.    In Emacs version 18, you need to load Edebug yourself; you can do
  971. this by putting the appropriate `load' command in your `.emacs' file.
  972.  
  973.    If you are reading this in Info, you can instrument the
  974. `triangle-recursively-bugged' function shown above.  `edebug-defun'
  975. fails to locate the bounds of a definition whose `defun' line is
  976. indented; so the example is presented without the usual spaces to the
  977. left of the `defun'.
  978.  
  979.    After instrumenting the function, place your cursor after the
  980. following expression and type `C-x C-e' (`eval-last-sexp'):
  981.  
  982.      (triangle-recursively-bugged 3)
  983.  
  984. You will be jumped back to the source for `triangle-recursively-bugged'
  985. and the cursor positioned at the beginning of the `if' line of the
  986. function.  Also, you will see an arrow at the left hand side of that
  987. line that looks like this: `=>'.  The arrow marks the line where the
  988. function is executing.
  989.  
  990.      =>-!-(if (= number 1)
  991.  
  992. In the example, the location of point is displayed as `-!-' (in a
  993. printed book, it is displayed with a five pointed star).
  994.  
  995. If you now press <SPC>, point will move to the next expression to be
  996. executed; the line will look like this:
  997.  
  998.      =>(if -!-(= number 1)
  999.  
  1000. As you continue to press <SPC>, point will move from expression to
  1001. expression.  At the same time, whenever an expression returns a value,
  1002. that value will be displayed in the echo area.  For example, after you
  1003. move point past `number', you will see the following:
  1004.  
  1005.      Result: 3 = C-c
  1006.  
  1007. This means the value of `number' is 3, which is ASCII <CTL-C> (the
  1008. third letter of the alphabet).
  1009.  
  1010.    You can continue moving through the code until you reach the line
  1011. with the error.  Before evaluation, that line looks like this:
  1012.  
  1013.      =>        -!-(1= number)))))               ; Error here.
  1014.  
  1015. When you press <SPC> once again, you will produce an error message that
  1016. says:
  1017.  
  1018.      Symbol's function definition is void: 1=
  1019.  
  1020. This is the bug.
  1021.  
  1022.    Press `q' to quit Edebug.
  1023.  
  1024.    To remove instrumentation from a function definition, simply
  1025. re-evaluate it with a command that does not instrument it.  For
  1026. example, you could place your cursor after the definition's closing
  1027. parenthesis and type `C-x C-e'.
  1028.  
  1029.    Edebug does a great deal more than walk with you through a function.
  1030. You can set it so it races through on its own, stopping only at an
  1031. error or at specified stopping points; you can cause it to display the
  1032. changing values of various expressions; you can find out how many times
  1033. a function is called, and more.
  1034.  
  1035.    Edebug is described in *Note Edebug: (elisp)edebug.
  1036.  
  1037. 
  1038. File: emacs-lisp-intro.info,  Node: Debugging Exercises,  Prev: edebug,  Up: Debugging
  1039.  
  1040. Debugging Exercises
  1041. ===================
  1042.  
  1043.    * Install the `count-words-region' function and then cause it to
  1044.      enter the built-in debugger when you call it.  Run the command on a
  1045.      region containing two words.  You will need to press `d' a
  1046.      remarkable number of times.  On your system, is a `hook' called
  1047.      after the command finishes?  (For information on hooks, see *Note
  1048.      Command Loop Overview: (elisp)Command Overview.)
  1049.  
  1050.    * Copy `count-words-region' into the `*scratch*' buffer, remove
  1051.      white space before the `defun' line if necessary, instrument the
  1052.      function for Edebug, and walk through its execution.  The function
  1053.      does not need to have a bug, although you can introduce one if you
  1054.      wish.  If the function lacks a bug, the walk-through completes
  1055.      without problems.
  1056.  
  1057.    * While running Edebug, type `?' to see a list of all the Edebug
  1058.      commands.  (The `global-edebug-prefix' is usually `C-x X', i.e.
  1059.      `<CTL>-x' followed by an upper case `X'; use this prefix for
  1060.      commands made outside of the Edebug debugging buffer.)
  1061.  
  1062.    * In the Edebug debugging buffer, use the `p'
  1063.      (`edebug-bounce-point') command to see where in the region the
  1064.      `count-words-region' is working.
  1065.  
  1066.    * Move point to some spot further down function and then type the
  1067.      `h' (`edebug-goto-here') command to jump to that location.
  1068.  
  1069.    * Use the `t' (`edebug-trace-mode') command to cause Edebug to walk
  1070.      through the function on its own; use an upper case `T' for
  1071.      `edebug-Trace-fast-mode'.
  1072.  
  1073.    * Set a breakpoint, then run Edebug in Trace mode until it reaches
  1074.      the stopping point.
  1075.  
  1076. 
  1077. File: emacs-lisp-intro.info,  Node: Conclusion,  Next: the-the,  Prev: Debugging,  Up: Top
  1078.  
  1079. Conclusion
  1080. **********
  1081.  
  1082.    We have now reached the end of this Introduction.  You have now
  1083. learned enough about programming in Emacs Lisp to set values, to write
  1084. simple `.emacs' files for yourself and your friends, and write simple
  1085. customizations and extensions to Emacs.
  1086.  
  1087.    This is a place to stop.  Or, if you wish, you can now go onward, and
  1088. teach yourself.
  1089.  
  1090.    You have learned some of the basic nuts and bolts of programming.
  1091. But only some.  There are a great many more brackets and hinges that are
  1092. easy to use that we have not touched.
  1093.  
  1094.    A path you can follow right now lies among the sources to GNU Emacs
  1095. and in *Note The GNU Emacs Lisp Reference Manual: (elisp)Top.
  1096.  
  1097.    The Emacs Lisp sources are an adventure.  When you read the sources
  1098. and come across a function or expression that is unfamiliar, you need to
  1099. figure out or find out what it does.
  1100.  
  1101.    Go to the Reference Manual.  It is a thorough, complete, and fairly
  1102. easy-to-read description of Emacs Lisp.  It is written not only for
  1103. experts, but for people who know what you know.  (The `Reference
  1104. Manual' comes with the standard GNU Emacs distribution.  Like this
  1105. introduction, it comes as a Texinfo source file, so you can read it
  1106. on-line and as a typeset, printed book.)
  1107.  
  1108.    Go to the other on-line help that is part of GNU Emacs: the on-line
  1109. documentation for all functions, and `find-tags', the program that
  1110. takes you to sources.
  1111.  
  1112.    Here is an example of how I explore the sources.  Because of its
  1113. name, `simple.el' is the file I looked at first, a long time ago.  As
  1114. it happens some of the functions in `simple.el' are complicated, or at
  1115. least look complicated at first sight.  The first function, for
  1116. example, looks complicated.  This is the `open-line' function.
  1117.  
  1118.    You may want to walk through this function slowly, as we did with the
  1119. `forward-sentence' function.  (*Note forward-sentence::.) Or you may
  1120. want to skip that function and look at another, such as `split-line'.
  1121. You don't need to read all the functions.  According to
  1122. `count-words-in-defun', the `split-line' function contains 27 words and
  1123. symbols.
  1124.  
  1125.    Even though it is short, `split-line' contains four expressions we
  1126. have not studied: `skip-chars-forward', `indent-to', `insert', and
  1127. `?\n'.
  1128.  
  1129.    Consider the `insert' function.  (It is mentioned in passing in
  1130. *Note Regexp Review::.) In Emacs, you can find out more about `insert'
  1131. by typing `C-h f' (`describe-function') and the name of the function.
  1132. This gives you the function documentation.  You can look at its source
  1133. using `find-tag', which is bound to `M-.' (this is not so helpful in
  1134. this case; the function is a primitive written in C rather than Lisp).
  1135. Finally, you can find out what the Reference Manual has to say by
  1136. visiting the manual in Info, and typing `i' (`Info-index') and the name
  1137. of the function, or by looking up `insert' in the index to a printed
  1138. copy of the manual.
  1139.  
  1140.    Similarly, you can find out what is meant by `?\n'.  You can try
  1141. using `Info-index' with `?\n'.  It turns out that this action won't
  1142. help; but don't give up.  If you search the index for `\n' without the
  1143. `?', you will be taken directly to the relevant section of the manual.
  1144. (*Note Character Type: (elisp)Character Type.  `?\n' stands for the
  1145. newline character.)
  1146.  
  1147.    You may be able to guess what is done by `skip-chars-forward' and
  1148. `indent-to'; or you can look them up, too.  (Incidentally, the
  1149. `describe-function' function itself is in `help.el'; it is one of those
  1150. long, but decipherable functions.  Its definition illustrates how to
  1151. customize the `interactive' expression without using the standard
  1152. character codes; and it shows how to create a temporary buffer.)
  1153.  
  1154.    Other interesting source files include `paragraphs.el',
  1155. `loaddefs.el', and `loadup.el'.  The `paragraphs.el' file includes
  1156. short, easily understood functions as well as longer ones.  The
  1157. `loaddefs.el' file contains the many standard autoloads and many
  1158. keymaps.  I have never looked at it all; only at parts.  `loadup.el' is
  1159. the file that loads the standard parts of Emacs; it tells you a great
  1160. deal about how Emacs is built.  (*Note Building Emacs: (elisp)Building
  1161. Emacs, for more about building.)
  1162.  
  1163.    As I said, you have learned some nuts and bolts; however, and very
  1164. importantly, we have hardly touched major aspects of programming; I
  1165. have said nothing about how to sort information, except to use the
  1166. predefined `sort' function; I have said nothing about how to store
  1167. information, except to use variables and lists; I have said nothing
  1168. about how to write programs that write programs.  These are topics for
  1169. another, and different kind of book, a different kind of learning.
  1170.  
  1171.    What you have done is learn enough for much practical work with GNU
  1172. Emacs.  What you have done is get started.  This is the end of a
  1173. beginning.
  1174.  
  1175. 
  1176. File: emacs-lisp-intro.info,  Node: the-the,  Next: Kill Ring,  Prev: Conclusion,  Up: Top
  1177.  
  1178. The `the-the' Function
  1179. **********************
  1180.  
  1181.    Sometimes when you you write text, you duplicate words--as with "you
  1182. you" near the beginning of this sentence.  I find that most frequently,
  1183. I duplicate "the'; hence, I call the function for detecting duplicated
  1184. words, `the-the'.
  1185.  
  1186.    As a first step, you could use the following regular expression to
  1187. search for duplicates:
  1188.  
  1189.      \\(\\w+[ \t\n]+\\)\\1
  1190.  
  1191. This regexp matches one or more word-constituent characters followed by
  1192. one or more spaces, tabs, or newlines.  However, it does not detect
  1193. duplicated words on different lines, since the ending of the first
  1194. word, the end of the line, is different from the ending of the second
  1195. word, a space.  (For more information about regular expressions, see
  1196. *Note Regular Expression Searches: Regexp Search, as well as *Note
  1197. Syntax of Regular Expressions: (emacs)Regexps, and *Note Regular
  1198. Expressions: (elisp)Regular Expressions.)
  1199.  
  1200.    You might try searching just for duplicated word-constituent
  1201. characters but that does not work since the pattern detects doubles
  1202. such as the two occurrences of `th' in `with the'.
  1203.  
  1204.    Another possible regular expression is for word-constituent
  1205. characters that are followed by non-word-constituent characters.  Here,
  1206. `\\w+' matches one or more word-constituent characters and `\\W*'
  1207. matches zero or more non-word-constituent characters.
  1208.  
  1209.      \\(\\(\\w+\\)\\W*\\)\\1
  1210.  
  1211. Again, not useful.
  1212.  
  1213.    Here is the pattern that I use.  It is not perfect, but good enough.
  1214. `\\b' matches the empty string, provided it is at the beginning or end
  1215. of a word; `[^@ \n\t]+' matches one or more occurrences of any
  1216. characters that are *not* an @-sign, space, newline, or tab.
  1217.  
  1218.      \\b\\([^@ \n\t]+\\)[ \n\t]+\\1\\b
  1219.  
  1220.    One can write more complicated expressions, but I found that this
  1221. expression is good enough, so I use it.
  1222.  
  1223.    Here is the `the-the' function, as I include it in my `.emacs' file,
  1224. along with a handy global key binding:
  1225.  
  1226.      (defun the-the ()
  1227.        "Search forward for for a duplicated word."
  1228.        (interactive)
  1229.        (message "Searching for for duplicated words ...")
  1230.        (push-mark)
  1231.        ;; This regexp is not perfect
  1232.        ;; but is fairly good over all:
  1233.        (if (re-search-forward
  1234.             "\\b\\([^@ \n\t]+\\)[ \n\t]+\\1\\b" nil 'move)
  1235.            (message "Found duplicated word.")
  1236.          (message "End of buffer")))
  1237.      
  1238.      ;; Bind `the-the' to  C-c \
  1239.      (global-set-key "\C-c\\" 'the-the)
  1240.  
  1241.    Here is test text:
  1242.  
  1243.      one two two three four five
  1244.      five six seven
  1245.  
  1246.    You can substitute the other regular expressions shown above in the
  1247. function definition and try each of them on this list.
  1248.  
  1249. 
  1250. File: emacs-lisp-intro.info,  Node: Kill Ring,  Next: Full Graph,  Prev: the-the,  Up: Top
  1251.  
  1252. Handling the Kill Ring
  1253. **********************
  1254.  
  1255.    The kill ring is a list that is transformed into a ring by the
  1256. workings of the `rotate-yank-pointer' function.  The `yank' and
  1257. `yank-pop' commands use the `rotate-yank-pointer' function.  This
  1258. appendix describes the `rotate-yank-pointer' function as well as both
  1259. the `yank' and the `yank-pop' commands.
  1260.  
  1261. * Menu:
  1262.  
  1263. * rotate-yank-pointer::         Move a pointer along a list and around.
  1264. * yank::                        Paste a copy of a clipped element.
  1265. * yank-pop::                    Insert first element pointed to.
  1266.  
  1267.